package com.xuhuan.demo.pattern.factory.simplefactory.pizzastore.order;

import com.xuhuan.demo.pattern.factory.simplefactory.pizzastore.pizza.Pizza;

import java.util.Scanner;

/**
 * @author huan.xu
 * @date 2021/10/3 21:54
 * @description 订购披萨
 */
public class OrderPizza {

    public OrderPizza(SimpleFactory simpleFactory) {
        setSimpleFactory(simpleFactory);
    }

    public void setSimpleFactory(SimpleFactory simpleFactory) {
        do {
            String orderType = getOrderType();
            if ("0".equals(orderType)) {
                System.out.println("退出订购！");
                break;
            }
            Pizza pizza = simpleFactory.createPizza(orderType);
            if (pizza != null) {
                System.out.println("下单成功！");
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            } else {
                System.out.println("没有您选择的披萨种类！");
                break;
            }
        } while (true);
    }

    private String getOrderType() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请选择要订购的披萨:cheese、greek、pepper，退出订购请输入：0");
        return scanner.next();
    }
}
